<template>
  <div id="blog-list">
    <Header></Header>
    
    <div class="block">
      <el-timeline>
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs">
          <el-card>
            <h4>
              <router-link :to="{name:'BlogDetail',params:{blogId:blog.id},props:true}">
                {{ blog.title }}
              </router-link>
            </h4>
            <p>{{ blog.description }}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
      <!--下面需要了解element文档了解-->
      <el-pagination
         class="blogs-pagenation"
         background
         layout="prev, pager, next"
         :current-page="currentPage"
         :page-size="pageSize"
         :total="total"
          @current-change="page">
      </el-pagination>

    </div>
    
  </div>
</template>

<script>
import Header from "@/components/Header";
export default {
  name: "Blogs",
  components: {Header},
  data(){
    return{
      blogs:{},
      currentPage:1,
      total:0,
      pageSize:5,
    }
  },
  methods:{
    page(currentPage){
      const _this=this;
      _this.$axios('/blog/all?currentPage='+currentPage).then(resp=>{
        console.log(resp);
        _this.blogs= resp.data.data.records;
        _this.total=resp.data.data.total;
        _this.currentPage=resp.data.data.current;
        _this.pageSize=resp.data.data.size;
      })
    }
  },
  
  
  created() {
    this.page(1);
  }
}

</script>

<style scoped>
.blogs-pagenation{
  margin: 0 auto;
  text-align: center;
}
</style>